#region Using Statements
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Storage;
#endregion

namespace MegaEngine.Source.Sprites
{
    class LevelEditorHighlight : Sprite
    {
        Vector4 colorVector;
        float greenGain = 1f;
        int colorIndex = 0;
        private bool xPressed = false;
        private bool yPressed = false;
        int xElapsed = 0;
        int yElapsed = 0;
        Color[] colors;
        int colorDirection = 1;
        long colorTimer = 0;
        public LevelEditorHighlight()
        {
            init();
            this.velocity = new Vector2(0.0f, 0.0f);
            this.color = Color.White;
            this.bounds.X = 0;
            this.bounds.Y = 0;
            this.bounds.Width = 32;
            this.bounds.Height = 32;
            this.numFrames = 1;
            this.levelOrigin.X = 0;
            this.levelOrigin.Y = 0;
            colorVector = new Vector4(255f, 0f, 0f, 0f);
            generateColorArray();
        }

        private void generateColorArray()
        {
            colors = new Color[]{
            Color.GreenYellow,
            Color.Chartreuse,
            Color.LawnGreen,
            Color.Lime,
            Color.LimeGreen,
            Color.ForestGreen,
			Color.DarkGreen,
			};
        }
        public override bool update(float xOrigin, float yOrigin, int width, int height, GameTime gameTime, ArrayList environment, Vector2 theOrigin)
        {
            xElapsed += gameTime.ElapsedGameTime.Milliseconds;
            if (xPressed)
            {
                xElapsed += gameTime.ElapsedGameTime.Milliseconds;
            }
            if (yPressed)
            {
                yElapsed += gameTime.ElapsedGameTime.Milliseconds;
            }

            Console.WriteLine(colorVector);
            return colorGlow(gameTime);
        }

        private bool colorGlow(GameTime gameTime)
        {
            colorTimer += gameTime.ElapsedGameTime.Milliseconds;
            if (colorTimer > 100)
            {
                colorTimer = 0;
                colorIndex += colorDirection;
            }
            if (colorIndex >= colors.Length - 1)
            {
                colorDirection = -1;
            }
            else if (colorIndex <= 0)
            {
                colorDirection = 1;
            }
            color = colors[colorIndex];
            return true;
        }

        public override Rectangle getBounds()
        {
            bounds.Width = getAnimationFrame().Width;
            bounds.Height = getAnimationFrame().Height;
            return bounds;
        }
        public override void onCollission(Sprite other)
        {
            Console.WriteLine("COLLISSION!");
        }

        public override void input()
        {
            KeyboardState keyboard = Keyboard.GetState();
            keyboard = Keyboard.GetState();
            if (keyboard.IsKeyDown(Keys.Right) && !xPressed)
            {
                xPressed = true;
                levelOrigin.X += 32;
            }
            else if (keyboard.IsKeyDown(Keys.Left) && !xPressed)
            {
                xPressed = true;
                levelOrigin.X -= 32;
            }
            if (keyboard.IsKeyDown(Keys.Up) && !yPressed)
            {
                yPressed = true;
                levelOrigin.Y -= 32;
            }
            else if (keyboard.IsKeyDown(Keys.Down) && (!yPressed))
            {
                yPressed = true;
                levelOrigin.Y += 32;
            }

            if (keyboard.IsKeyUp(Keys.Left) && keyboard.IsKeyUp(Keys.Right) || xElapsed > 50)
            {
                xPressed = false;
                xElapsed = 0;
            }
            if (keyboard.IsKeyUp(Keys.Up) && keyboard.IsKeyUp(Keys.Down) || yElapsed > 50)
            {
                yPressed = false;
                yElapsed = 0;
            }

        }
        public override ArrayList getCollisionBox()
        {
            ArrayList result = new ArrayList();
            return result;
        }
        public override void updateAnimationState()
        {

        }
    }
}
